<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<%@ include file="/inc.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>善定制 - 确认订单</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />    
    <!-- Bootstrap -->
    <link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <!-- style -->
    <link href="<%=basePath%>css/home.css" rel="stylesheet">
  </head>
  <body>
      <div class="alert alert-danger" role="alert" id="error" style="display:none"><i class="fa fa-exclamation-triangle"></i> gggggggg</div>
  <s:if test='error != null'>						
		 <div class="error">
          <div class="alert alert-danger" role="alert"><i class="fa fa-exclamation-triangle"></i> <s:property value="error" /></div>
        </div><!--E .error-->
								</s:if>
									<form class="form-horizontal" id="form"
									action="<%=basePath%>public/orderSingleAction!pay.action"
									method="post" encType="multipart/form-data">
									<s:hidden name="brand_id"></s:hidden>
									<s:hidden name="cloth_id"></s:hidden>
										<s:hidden name="openid"></s:hidden>
    <div class="container-fluid">
      <div class="wrap">
       <div class="order-list">
		<div class="row">
            <div class="col-xs-3"><img src="<%=basePath_org%><s:property value="cloth.img" />" alt=""></div>
            <div class="col-xs-9">
              <div class="name"><s:property value="cloth.name" /></div>
              <p class="red">价格：<s:property value="brand.price" />元</p>
            </div>
          </div>
        </div><!--E .order-list-->
        <div class="dizhi">
          <h3>收货地址</h3>
          <div class="form-group has-error">
              <s:textfield id="name" name="name" 
												cssClass="form-control" placeholder="收货人"/>
          </div>
          <div class="form-group has-error">
            <s:textfield id="address" name="address" 
												cssClass="form-control" placeholder="收货地址"/>
          </div>
          <div class="form-group has-error">
            <s:textfield id="phone" name="phone" 
												cssClass="form-control" placeholder="手机号"/>
          </div>
          <label class="checkbox-inline">
            <input type="checkbox" id="binding" name="binding" value="true">
             是否绑定手机号
          </label> 
        </div><!--E .dizhi-->
        <button type="button" class="btn btn-org btn-lg btn-block" onclick="CreateOrder()">微信支付</button>
      </div><!--E .wrap-->
        
    </div>
    </form>
    
    <script src="<%=basePath%>js/jquery-1.10.1.min.js"></script>
            
            <script>
            function CreateOrder() {
            	 var errorDiv = document.getElementById("error");
            	 errorDiv.style.display = "none";
            	 var name = document.getElementById('name').value;
            	 if(!name) {//a为null 或者"" 或者0 
            		 document.getElementById('error').innerHTML='请输入收货人';
            		 errorDiv.style.display = "block";
            		 return;
            	}
            	 var address = document.getElementById('address').value;
            	 if(!address) {//a为null 或者"" 或者0 
            		 document.getElementById('error').innerHTML='请输收货地址';
            		 errorDiv.style.display = "block";
            		 return;
            	}
            	 var phone = document.getElementById('phone').value;
            	 if(!phone) {//a为null 或者"" 或者0 
            		 document.getElementById('error').innerHTML='请输手机号';
            		 errorDiv.style.display = "block";
            		 return;
            	}
            	
			 var brand_id = document.getElementById('brand_id').value;
			 var binding = document.getElementById('binding').value;
			 var openid = document.getElementById('openid').value;
			var cloth_id = document.getElementById('cloth_id').value;
			$.ajax({
				type:'post',
				url:'<%=basePath%>public/orderSingleAction!pay.action',
				dataType : 'json', 
				data : {"cloth_id":cloth_id,"brand_id":brand_id,"name":name,"address":address,"phone":phone,"openid":openid,"binding":binding},
				timeout:60000,
				success: function (json_str){
					  var temp = eval(json_str);  
					  WeixinJSBridge.invoke('getBrandWCPayRequest',
									  	   {
									  	   "appId" : temp.appId,     //公众号名称，由商户传入     
								           "timeStamp":temp.timeStamp,         //时间戳，自1970年以来的秒数     
								           "nonceStr" : temp.nonceStr, //随机串     
								           "package" : temp.package,     
								           "signType" : "MD5",         //微信签名方式:     
								           "paySign" : temp.paySign//微信签名 
									  	   },
									  	  function(res){
					                          if(res.err_msg == "get_brand_wcpay_request:ok" ) {
					                          
					                          }else{
					                          	alert("交易失败!");
					                          }
					                          // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
					                          //因此微信团队建议，当收到ok返回时，向商户后台询问是否收到交易成功的通知，若收到通知，前端展示交易成功的界面；若此时未收到通知，商户后台主动调用查询订单接口，查询订单的当前状态，并反馈给前端展示相应的界面。
				                          }); 
				}
			});
				}  
	
 </script>
  </body>
</html>